<!-- /* Description for file.
 *客户管理添加
 *
 * @copyright     Copyright 2008-2010, PHInfo Services Inc. (http://www.phinfoservices.com)
 * @package       ues
 * @subpackage    ues/app/views/companymanages
 * @since         ues
 * @version       V0.0.1
 * @modifiedby    会兵2011年0807
 * @lastmodified  会兵2011年0807
 -->
<?php
echo $html->css ( 'style' );
echo $html->css ( 'tab' );
echo $html->css('start/jquery-ui-1.8.2.custom');
echo $javascript->link('jquery-ui-1.8.2.custom.min');
echo $html->css ( 'jquery-validate/css/screen' );
?>

<script type="text/javascript">
	$(function(){
		$(".datepickerSpan :input").datepicker({
			inline: true
		});
		 $('.datepickerSpan :input').datepicker('option', {dateFormat: "yy-mm-dd"});
		 $('.datepickerSpan :input').datepicker( "option", "closeText", 'X' );
	});
</script>

<script type="text/javascript">
$(document).ready(function(){
	$("#close").click(function(){
	window.close();
	});
});
//$(document).ready(function(){
//	$("#cancel").click(function(){
//		$("#CompanymanageAddForm").reset();
//		});
//	$("#btnajaxAdd").click(function(){		
//						$("#CompanymanageAddForm").submit();
//					}
//					);
//	});



//打开用户选择框
$(function()
		{
			$("#allowpersons").click(function(){		
				$(".toolbarStyle").toggle();
			});
			$("#closeallowperson").click(function(){		
				$(".toolbarStyle").toggle();
			});
			$("#closeallowperson").click(function(){		
				$(".toolbarStyle").attr('style').attr('display').val('none');
			});
			
		});
//选择用户提交
$(function()
		{
			$("#addallowperson").click(function(){		
				getDelStr();
				$(".toolbarStyle").toggle();
			});
		});

//用来将选中的用户拼接起来
function getDelStr() {
	var delArr = $(":checkbox:checked");
	if(delArr.length==0)
	{
		alert("请选择用户!");
		return;
	}
	var str = "";
	for(var i=0;i<delArr.length;i++) {
		var del = delArr[i].value;
		str += del;
		str += ",";
	}
	$("#VisitorlistAllowperson").val(str);
}


//行业二级菜单
$(document).ready(function(){
	$("#CompanymanageIndustry1").change(function(){
		var IndustryDroptoplist = $(this).val();
		if(IndustryDroptoplist!="")
		{
			$.post("<?php echo ROOT_WEB_PATH; ?>/industries/industriesQuery/",{
				Industry : $(this).val()
				},
			function(data,textStatus){
					 $("#CompanymanageIndustry2:eq(0)>option").remove();
					 $(data).find("aaa").each(function(){
					 //alert($(this).attr("name"));
					 $("#CompanymanageIndustry2:eq(0)").append("<option></option>");
					 $("#CompanymanageIndustry2:eq(0)>option:last").val($(this).text()).html($(this).text());
				  });
				});
		}
	});
	$("#CompanymanageAddvisitorcomForm").bind("submit", function() { 
		var value = "";
		if($("#CompanymanageIndustry1 option:selected").text()!="不限")
		value = $("#CompanymanageIndustry1 option:selected").text();
		if($("#CompanymanageIndustry2 option:selected").text()!="不限"&&$("#CompanymanageIndustry2 option:selected").text()!="--")
		value += '_'+$("#CompanymanageIndustry2 option:selected").text();
		$("#CompanymanageIndustry").val(value); });
});

//关键字
$(document).ready(
function()
{
	//添加
	$("#addKeyName").click(
		function()
		{
			var add = $("#keyInput").val();
			var o = $("<option>"+add+"</option>");
			$("#keyOption").append(o);
			var keys ='';
			for(var i = 0; i < $("#keyOption").children().length; i++ )
			{
				keys+=$("#keyOption").children()[i].text + "/";
			}
			$("#keyValue").attr('value',keys);
			//alert($("#keyOption").children().length);
			//alert($("#keyOption").children()[0].text);
		});
	//删除
	$("#delKeyName").click(
		function()
		{
			$("#keyOption option:selected").remove();
		});	
});


//检测重名
$(document).ready(
	function()
	{
		$("#checkname").click(
			function()
			{
				$.post("<?php echo ROOT_WEB_PATH; ?>/companymanages/sameName/",{
				model : "Companymanage",
				name : $("#shortname").val()
				},function(data,textStatus){	
				$(data).find("aaa").each(function(){
						if($(this).text()=="false")
						{
							alert("公司简称重名");
						} else {
							alert("可以添加");
						}
				});			
			});
	});
	  $("#addallowperson").click(
			function()
			{
				var appstr="";
				$("input:checked").each(function(){
					var name=$(this).val();
					appstr+="/"+name+"/";
				});
				$(".allo").val(appstr);
			}
				
		);
});


//添加验证
$(document).ready(function() {

	//验证是否必填
	function test(id)
	{
		var srt = "font#" + id;
		var isValidate =  $(srt).text();
		var validate = $.trim(isValidate);
		if(validate == "*"){
			return true;
		} else {
			return false;
		}
	}

	$.validator.setDefaults({       
		 submitHandler: function(form) {    
		  form.submit();    
		}       
	});   
			
// validate signup form on keyup and submit
$("#CompanymanageAddvisitorcomForm").validate({
rules: {
"data[Companymanage][name]" : {
required: test("name"),string:true,stringMinLength:0,stringMaxLength:50
},
"data[Companymanage][companyCode]": {
required: test("companyCode"),string:true,minlength:0,maxlength:50
},
"data[Companymanage][tel]": {
required: test("tel"),phone:true
},
"data[Companymanage][industry]": {
required: test("industry"),selectNone:true
},
"data[Companymanage][companyProperty]": {
required: test("companyProperty"),selectNone:true
},
"data[Companymanage][companyType]": {
required: test("companyType"),selectNone:true
},
"data[Companymanage][shortname]": {
required: true,string:true,stringMinLength:0,stringMaxLength:50
},
"data[Companymanage][url]": {
required: false,url:true
},
"data[Companymanage][keyInput]": {
required: false,string:true,stringMinLength:0,stringMaxLength:50
},
"data[Companymanage][fax]": {
required: false,fax:true
},
"data[Companymanage][warranty]": {
required: false,dateISO:true
},
"data[Companymanage][product]": {
required: false,string:true,stringMinLength:0,stringMaxLength:50
},
"data[Companymanage][location]": {
required: false,string:true,stringMinLength:0,stringMaxLength:50
},
"data[Companymanage][postCode]": {
required: false,zipCode:true
},
"data[Companymanage][address]": {
required: false,string:true,stringMinLength:0,stringMaxLength:50
},
"data[Companymanage][allowperson]": {
required: true
},
"data[Companymanage][other]": {
required: false,stringMinLength:0,stringMaxLength:50
},
"data[Companymanage][memo]": {
required: false,stringMinLength:0,stringMaxLength:200
},
"data[Companymanage][linkmanlinkman]": {
required: false,string:true,stringMinLength:0,stringMaxLength:50
},
"data[Companymanage][linkmanenglishName]": {
required: false,englishName:true
},
"data[Companymanage][linkmandepartment]": {
required: false,string:true,stringMinLength:0,stringMaxLength:50
},
"data[Companymanage][linkmanposition]": {
required: false,string:true,stringMinLength:0,stringMaxLength:50
},
"data[Companymanage][linkmanemail]": {
required: false,email:true
},
"data[Companymanage][linkmanfax]": {
required: false,fax:true
},
"data[Companymanage][linkmanmobilePhone]": {
required: false,mobile:true
},
"data[Companymanage][linkmantel]": {
required: false,phone:true
},
"data[Companymanage][linkmanbirthday]": {
required: false,dateISO:true
},
"data[Companymanage][linkmanmemo]":{
required: false,stringMinLength:0,stringMaxLength:200
}
},
messages: {
},

focusInvalid:false,
onkeyup:false,
errorPlacement:function(error, element){
	error.appendTo(element.parent());
}
});

//	$("#df").validate({
//	
//	});
});

$(document).ready(function(){

//提交时对公司简称进行检测
function verifyName(){
var shorName=$("#shortname").val();
var param= [{name:"model",value:"Companymanage"},{name:"name",value:shorName}];
if(shorName!=""){
	flag=true;
	$.ajax({
		  type: 'POST',
		   url: "<?php echo ROOT_WEB_PATH; ?>/companymanages/sameName/",
		   async: false,
		   data: param,
		   dataType:"xml",
		   success: function(xml)
		   {
		  		$(xml).find("aaa").each(function(i){
		  			 var id = $(this).text();
					 if(id == "false")
					 {
						 flag=false;
						 return false;
					 };
		  		});
		   }
		 });
	return flag;
	}
else {

}

}
//提交
$(".addsubmit").click(function(){
	
	if(verifyName() == false){
		alert("公司简称不能重复");
	} else {
		//alert('submit');
		$("#CompanymanageAddvisitorcomForm").submit();
	}
	});
});

//自动生成客户编号
$(document).ready(
	function()
	{
		$("#creatCode").click(
			function()
			{
			    var user="<?php echo $user; ?>";
				var date="<?php echo $date;?>";
				var thecode = user+date;
				$("#CompanymanageCompanyCode").val(thecode);//将生成的code设置到输入框中
			});
	});

</script>
<style>
.input{float:left}
</style>
<!-- 当前位置-->
<div id="tabmenubar">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td class="tabmenubartitle1"><?php echo  __('YourPosition');//您现在的位置：?></td>
		<td class="tabmenubartitle2"><?php echo __('Visitor Management');//一级目录
										   echo '>';echo __('Visitor Company Management');//一级目录
										   echo '>';?>
									<?php echo $html->tag('span', __('Visitor Company Management Add',true));//当前操作地用span加粗?> 						  
		</td>
	</tr>
</table>
</div>
<!-- 当前位置-->


<!-- 允许查看人弹出 -->
<div class="toolbarStyle" style="display:none">
<iframe style="position:absolute;top:0;left:0;width:100%;height:100%;filter:alpha(opacity=0);z-index:-1;"></iframe>
	<?php 
		foreach ($users as $eachrecord)
		{

			echo "<input type='checkbox' class='choose' value='".$eachrecord['User']['username']."'></input>";
			echo $eachrecord['User']['username'];
			//echo $form->checkbox($eachrecord['User']['username'], array('value' => $eachrecord['User']['username']));
			
		}
	?>
<table width="100%" cellspacing="0" cellpadding="0" border="0" style="text-align: left">
	<tr>
		<td width="50"></td>
		<td width="100"><?php echo $form->button('确定',array('class'=>'oksubmit','id'=>'addallowperson'));?>  <!-- __('reset', true)取消-->
		<td width="100"><?php echo $form->button('关闭',array('class'=>'cancelbutton','id'=>'closeallowperson'));?>  <!-- __('reset', true)取消-->
	</tr>
</table>
</div>
<!-- //允许查看人弹出-->

<div class="tabflex">
	<?php echo $form->create('Companymanage',array('action'=>'addvisitorcom','type'=> 'post'));?>
		<fieldset><legend><?php __('基本信息');?></legend>
		<table width="100%" cellspacing="0" cellpadding="0" border="0" style="text-align: left;font-size:12px;">
			<tr>
			<td>
			<?php
				echo $form->hidden('creater');
				echo $form->hidden('updater');?> </td>
			</tr>
			
			<!--所属行业-->
			<tr>
				<td></td>
				<td ><?php __('所属行业');?>:
				<font color="red" id="industry">
					<?php 
						if($fields['industry'] == 1 && $fields['industry'] !=null)
						{
							echo "*";	
						}
					?>
				</font>	
				</td>
				<td >
				<?php $options1 = array();
							foreach($industries as $eachrecord1)
							{
								$options1[$eachrecord1['Industry']['id']] = $eachrecord1['Industry']['name'];
							}
							echo $form->input('industry1',array('empty' =>'不限','options'=>$options1,'label'=>false,'div'=>false,'class'=>'sitems'));		
				?>
				<?php echo $form->input('industry2',array('options'=>array('0'=>'--'),'label'=>false,'div'=>false,'class'=>'sitems'));		
				?>
				<?php 
					echo $form->hidden('industry');
				?>
				</td>
				<td></td>
				<td>
				<?php __('公司名称');?>:
				<font color="red" id="name">
					<?php 
						if($fields['name'] == 1 && $fields['name'] !=null)
						{
							echo "*";	
						}
					?>
				</font>				
				</td>
				<td colspan="2">
				<?php echo $form->input('name',array('class' => 'TextBoxE1','label'=>false,'id'=>'name'));?>
				</td>
			</tr>
			<!--//所属行业-->
		
			<!--企业性质-->
			<tr>
				<td></td>
				<td><?php __('企业性质');?>:
				<font color="red" id="companyProperty">
					<?php 
						if($fields['companyProperty'] == 1 && $fields['companyProperty'] !=null)
						{
							echo "*";	
						}
					?>
				</font>	
				</td>
				<td colspan="1">
				<?php $options2 = array();
							foreach($firmattributes as $eachrecord2)
							{
								$options2[$eachrecord2['Firmattribute']['name']] = $eachrecord2['Firmattribute']['name'];
							}
							echo $form->input('companyProperty',array('empty' =>'不限','options'=>$options2,'label'=>false,'div'=>false,'class'=>'TextBoxE1'));		
				?>
				</td>
				<td></td>
				<td><?php __('企业类型');?>:
								<font color="red" id="companyType">
					<?php 
						if($fields['companyType'] == 1 && $fields['companyType'] !=null)
						{
							
						}
					?>
				</font>	
				</td>
				<td colspan="2">
				<?php 
					echo $form->input('companyType',array('label'=>false,'default'=>'寻访客户','readonly'=>true));		
				?>
				</td>
			</tr>
			<!--//企业性质-->
			
			<!--公司名称、客户编号-->
			<tr>
				<td width="5%"></td>
				<td width="10%"><?php __('公司简称');?>:<font color="red">*</font></td>
				<td width="35%" coslpan="2">
				<?php echo $form->input('shortname',array('class' => 'TextBoxE1','label'=>false,'id'=>'shortname'));?>
					<?php echo "<input type='button' value='检测重复' class='btn4' id='checkname' ></input>"?>
				</td>
				<td></td>
				<td width="10%"><?php __('客户编号');?>:
				<font color="red" id="companyCode">
					<?php 
						if($fields['companyCode'] == 1 && $fields['companyCode'] !=null)
						{
							echo "*";	
						}
					?>
				</font>	
				</td>
				<td width="40%" colspan="2">
				<?php echo $form->input('companyCode',array('class' => 'TextBoxE1','label'=>false));?>
					<?php echo "<input type='button' value='自动生成' class='btn4' id='creatCode' ></input>" ;
					?>
				</td>
			</tr>
			<!--//公司名称、客户编号-->
			<tr>
				<td></td><td></td>
				<td colspan="6" style="color:gray">确定添加前请先“检查重复”</td>
			</tr>
			<!--公司网址、联系电话-->
			<tr>
				<td></td>
				<td><?php __('公司网址');?>:</td>
				<td colspan="1">
				<?php echo $form->input('url',array('class' => 'TextBoxE1','label'=>false));?>
				</td>
				<td></td>
				<td><?php __('联系电话');?>:
								<font color="red" id="tel">
					<?php 
						if($fields['tel'] == 1 && $fields['tel'] !=null)
						{
							echo "*";	
						}
					?>
				</font>	
				</td>
				<td colspan="2">
				<?php echo $form->input('tel',array('class' => 'TextBoxE1','label'=>false));?>
				</td>
			</tr>
			<!--//公司网址、联系电话-->
			
			<!--客户传真、公司产品-->
			<tr>
				<td></td>
				<td><?php __('客户传真');?>:</td>
				<td colspan="1">
				<?php echo $form->input('fax',array('class' => 'TextBoxE1','label'=>false));?>
				</td>
				<td></td>
				<td><?php __('公司产品');?>:</td>
				<td colspan="2">
				<?php echo $form->input('product',array('class' => 'TextBoxE1','label'=>false));?>
				</td>
			</tr>
			<!--//客户传真、公司产品-->
			
			<!--地区、客户状态-->
			<tr>
				<td></td>
				<td><?php __('地区');?>:</td>
				<td colspan="1">
				<?php echo $form->input('location',array('class' => 'TextBoxE1','label'=>false));?>
				</td>
				<td></td>
				<td ><?php __('客户状态');?>:</td>
				<td colspan="2">
				<?php $options = array();
							foreach($customerStatues as $eachrecord)
							{
								$options[$eachrecord['Customerstate']['customerStateName']] = $eachrecord['Customerstate']['customerStateName'];
							}
							echo $form->input('customerStatues',array('empty' =>'不限','options'=>$options,'label'=>false,'div'=>false,'class'=>'TextBoxE1'));		
				?>
				</td>
			</tr>
			<!--//地区、客户状态-->
			
			<!--客户地址、邮政编码-->
			<tr>
				<td></td>
				<td><?php __('客户地址');?>:</td>
				<td colspan="1">
				<?php echo $form->input('address',array('class' => 'TextBoxE1','label'=>false));?>
				</td>
				<td></td>
				<td><?php __('邮政编码');?>:</td>
				<td colspan="2">
				<?php echo $form->input('postCode',array('class' => 'TextBoxE1','label'=>false));?>
				</td>
			</tr>
			<!--//客户地址、邮政编码-->
			
			<!--允许查看人、保证期-->
			<tr>
				<td></td>
				<td><?php __('允许查看人');?>:<font color="red">*</font></td>
				<td>
					<?php 	
						echo $form->input('allowperson',array('label'=>false, 'class'=>'allo',"readonly"=>"true",'default'=>'/'.$user.'/'));
					?> 
					<?php 	
						echo $form->button('允许人',array('class'=>'oksubmit','id'=>'allowpersons'));
					?> 
				</td>
				<td></td>
				<td><?php __('保证期');?>:</td>
				<td colspan="2">
				<span class="datepickerSpan"><!--
				<?php echo $form->input('warranty',array('class' => '','label'=>false));?>
				--><div class="input text"><input name="data[Companymanage][warranty]" type="text" class="TextBoxE1" value="" id="CompanymanageWarranty" /></div>
				</span>
				</td>
			</tr>
			<!--//允许查看人、保证期-->
			</table>
			</fieldset>
			
			<fieldset><legend><?php __('其他信息/备注');?></legend>
			<table width="100%" cellspacing="0" cellpadding="0" border="0" style="text-align: left">
			<tr>
				<td></td>
				<td><?php __('其他信息');?>:</td>
				<td colspan="2">
					<?php echo $form->textarea('other',array('class' => 'TextBoxH','label'=>false));?>
				</td>
			</tr>
			<tr>
				<td></td>
				<td><?php __('客户备注');?>:</td>
				<td colspan="2">
					<?php echo $form->textarea('memo',array('class' => 'TextBoxH','label'=>false));?>
				</td>
			</tr>
			<tr>
				<td></td>
				<td><?php __('公司名称关键字');?>:</td>
				<td>
					<?php echo $form->input('keyInput',array('class' => 'TextBoxH','id'=>'keyInput','label'=>false));?>
					<?php echo $form->input('nameKeyWords',array('id'=>'keyValue','label'=>false,'type'=>'hidden', 'value'=>''));?>
				</td>
				<td><?php echo "<input type='button' class='newsubmit' value='添加' id='addKeyName'"?></td>
			</tr>
			<tr>
				<td width="5%"></td>
				<td width="10%"></td>
				<td width="30%">
					<?php 
					$toplistOptions = array();
					echo $form->input('',array('options'=>$toplistOptions,'label'=>false,'id'=>'keyOption','div'=>false,'class'=>'TextBoxH','size'=>5));?>
				</td>
				<td><?php echo "<input type='button' class='deletebutton' value='删除' id='delKeyName'"?></td>
			</tr>
		</table>
		</fieldset>
		
		<fieldset><legend><?php __('联系人信息');?></legend>
		<table width="100%" cellspacing="0" cellpadding="0" border="0" style="text-align: left">
			<tr>
				<td width="5%"></td>
				<td width="10%"><?php __('联系人名');?>:</td>
				<td>
					<?php echo $form->input('linkmanlinkman',array('class' => 'TextBoxH','label'=>false));?>
				</td>
			</tr>
				<tr>
				<td></td>
				<td ><?php __('英文简称');?>:</td>
				<td >
					<?php echo $form->input('linkmanenglishName',array('class' => 'TextBoxH','label'=>false));?>
				</td>
			</tr>
			<tr>
				<td ></td>
				<td><?php __('生&nbsp;&nbsp;&nbsp;&nbsp;日');?>:</td>
				<td >
				<span class="datepickerSpan">
					<?php echo $form->input('linkmanbirthday',array('class' => 'TextBoxH','label'=>false));?>
				</span>
				</td>
				<td>
				</td>
			</tr>
			<tr>
				<td ></td>
				<td><?php __('所属部门');?>:</td>
				<td >
					<?php echo $form->input('linkmandepartment',array('class' => 'TextBoxH','label'=>false));?>
				</td>
			</tr>
			<tr>
				<td></td>
				<td ><?php __('所在职位');?>:</td>
				<td >
					<?php echo $form->input('linkmanposition',array('class' => 'TextBoxH','label'=>false));?>
				</td>
			</tr>
				<tr>
				<td ></td>
				<td><?php __('联系电话');?>:</td>
				<td >
					<?php echo $form->input('linkmantel',array('class' => 'TextBoxH','label'=>false));?>
				</td>
			</tr>
			<tr>
				<td></td>
				<td><?php __('联系手机');?>:</td>
				<td >
					<?php echo $form->input('linkmanmobilePhone',array('class' => 'TextBoxH','label'=>false));?>
				</td>
			</tr>
				<tr>
				<td ></td>
				<td ><?php __('企业传真');?>:</td>
				<td >
					<?php echo $form->input('linkmanfax',array('class' => 'TextBoxH','label'=>false));?>
				</td>
			</tr>
			<tr>
				<td ></td>
				<td ><?php __('邮箱地址');?>:</td>
				<td >
					<?php echo $form->input('linkmanemail',array('class' => 'TextBoxH','label'=>false));?>
				</td>
			</tr>
				<tr>
				<td ></td>
				<td ><?php __('是否关键');?>:</td>
				<td >
					<?php 
					$op = array(''=>'未设','0'=>'否','1'=>'是');
					echo $form->input('linkmaniskey',array('options'=>$op, 'label'=>false));
					?>
				</td>
			</tr>
			<tr>
				<td></td>
				<td ><?php __('联系人备注信息');?>:</td>
				<td >
					<?php echo $form->textarea('linkmanmemo',array('class' => 'TextBoxH','label'=>false));?>
				</td>
			</tr>
		</table>
		</fieldset>
		
		<table width="100%" cellspacing="0" cellpadding="0" border="0" style="text-align: center">
			<tr>
				<td width="50"></td>
				<td width="100">
					<?php 
						echo "<input type='button' class='addsubmit' value='确定'/>";?>
				</td>
				<td width="100">		
					<?php	echo "<input type='reset' class='resetsubmit' value='重置'/>";			
					?>
				</td>
				<td width="100">		
					<?php	echo "<input type='button' class='cancelbutton' id='close' value='关闭'/>";			
					?>
				</td>
			</tr>
		</table>
			
	<?php echo $form->end();?>
</div>
 